package com.pro.xwt.common.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.pro.xwt.common.example.RProjFlowExample;
import com.pro.xwt.common.mapper.BTaskMapper;
import com.pro.xwt.common.mapper.RProjFlowMapper;
import com.pro.xwt.common.model.RProjFlow;
import com.pro.xwt.common.service.RProjFlowService;
@Service("rProjFlowService")
public class RProjFlowServiceImpl extends AbstractService<RProjFlow, String> implements RProjFlowService{

	@Autowired
	RProjFlowMapper rProjFlowMapper;
	@Autowired
	BTaskMapper bTaskMapper;
	@Override
	public List<RProjFlow> selectFlowByProject(String Pid) {
		// TODO Auto-generated method stub
		return rProjFlowMapper.selectFlowByProject(Pid);
	}

	@Override
	public int updateProjectFlowList(String proId, List<RProjFlowExample> list) {
		for (Object rProjFlowExample : list) {
			RProjFlowExample item = (RProjFlowExample) JSON.parseObject(rProjFlowExample.toString(),
					RProjFlowExample.class);
			RProjFlow rProjFlow = new RProjFlow();
			rProjFlow.setProjId(proId);
			rProjFlow.setSort(item.getSort());
			rProjFlow.setId(item.getId());
			int flag = rProjFlowMapper.update(rProjFlow);
			if(flag==0){
				return 0;
			}
		}
		return 1;
	}

	@Override
	public int deleteFlowById(String id) {
		int flag=rProjFlowMapper.deleteById(id);
		flag = bTaskMapper.deleteFlowById(id);
		return flag;
	}

}
